package com.tm.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tm.article.Dto.ArticleDto;
import com.tm.article.service.ArticleSerivce;
import com.tm.media.model.entity.ArticleEntity;
import com.tm.media.model.mapper.ArticleMapper;
import com.tm.media.utils.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleSerivceImpl extends ServiceImpl<ArticleMapper, ArticleEntity> implements ArticleSerivce {
    @Autowired
   private ArticleMapper articleMapper;
    @Override
    public Result loadArticle(ArticleDto articleDto) {
        String tableName="";
        if (articleDto.getTag().equals("1")){
            tableName="JAVA";
        }else if (articleDto.getTag().equals("2")){
            tableName="Python";
        }else if (articleDto.getTag().equals("3")){
            tableName="VUE";
        }else if (articleDto.getTag().equals("4")){
            tableName="WEEX";
        }else if (articleDto.getTag().equals("5")){
            tableName="大数据";
        }else if (articleDto.getTag().equals("6")){
            tableName="Docker";
        }else if (articleDto.getTag().equals("0")){
            tableName="其它";
        }else if (articleDto.getTag().equals("__dyna__")){
            tableName="动态";
        }else if (articleDto.getTag().equals("__all__")){
            tableName="推荐";
        }
        QueryWrapper<ArticleEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("channel_name",tableName);
        List<ArticleEntity> entities = articleMapper.selectList(queryWrapper);
        return Result.SUCCESS(entities);
    }

    @Override
    public Result load_article_behavior(ArticleEntity article) {
        QueryWrapper<ArticleEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("author_id",article.getAuthorId());
        queryWrapper.eq("id",article.getArticle_id());

        return Result.SUCCESS(articleMapper.selectOne(queryWrapper));
    }
}
